<% layout('/layouts/default.html', {title: '报表管理', libs: ['dataGrid']}){ %>
<style>
	.ui-jqgrid .actions>a i {
		font-size: 20px;
	}
</style>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title" style="white-space: nowrap">
				<i class="fa fa-list-alt"></i> (${startTime}至${endTime})${text('所有代理报表')}
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${member}" action="${ctx}/vip/record/listAgentData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
			<div class="form-group">
					<label class="control-label">起始时间：</label>
					<div class="control-inline">
						<input id="startTime" name="startTime" value="${startTime}" readonly="readonly" maxlength="20" class="form-control Wdate-date"
						dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,onpicked:function(){createDate_lte.click()}});"/>
						&nbsp;--&nbsp;
						<input id="endTime" name="endTime" value="${endTime}" readonly="readonly" maxlength="20" class="form-control Wdate-date"
						dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					</div>
				</div>
				<div class="form-group">
					<button id="btn" type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<div class="box-title" id="countTitle" style="padding:4px;text-align:center;font-size:15px;">
			</div>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text('账号')}', name:'loginName', index:'a.loginName', width:80, align:"center", frozen:true, formatter: function(val, obj, row, act){

		    return '<a href="${ctx}/vip/record/memberRecord?userCode='+row.userCode+'&startTime='+$('#startTime').val()+
				'&endTime='+$('#endTime').val()+ '" class="btnList" data-title="${text('所有会员流水账')}">'+(val||row.id)+'</a>';
		}},
        {header:'${text('代理名称')}', name:'name', index:'a.name', width:80, align:"center"},
        {header:'${text('入货/出货')}', name:'out', sortable:false, width:120, align:"center", formatter: function(val, obj, row, act){
            	var str = "<span>入："+formatNumber(row.in)+"</span></br>"+ "<span>出："+formatNumber(val)+"</span>";
                return str;
            }},
		{header:'${text('总充值/总支出/积分')}', name:'rechargeTotal',sortable:false, width:150, align:"center", formatter: function(val, obj, row, act){
			return "<span>充："+formatNumber(val)+"</span></br>" + "<span>支："+formatNumber(row.out)+"</span></br>" +
				"<span>积："+formatNumber(row.points)+"</span>";
		}}
	],
    showRownum: false,
	// 加载成功后执行事件
	ajaxSuccess: function(data){
        buildCount(data.otherData);
	}
});
$('#btnExport').click(function(){
    js.ajaxSubmitForm($('#searchForm'), {
        url:'${ctx}/vip/record/listAgentData?exportCode=1',
        downloadFile:true
    });
});
$(document).ready(function(){
    $("#btn").click();
});
//统计数据标题
function buildCount(countData){
    if(countData == undefined){
        $('#countTitle').html("统计数据为空");
        return;
    }
    var inTitle ="总入货:"+formatNumber(countData.in)+"&nbsp&nbsp&nbsp";
    var outTitle ="总出货:"+formatNumber(countData.out)+"&nbsp&nbsp&nbsp";
    var rechargeTitle ="总充值:"+formatNumber(countData.rechargeTotal)+"&nbsp&nbsp&nbsp";
    var pointsTitle ="总积分:"+formatNumber(countData.points)+"&nbsp&nbsp&nbsp";
    var payTitle = "总支出:"+formatNumber(countData.payTotal)+"&nbsp&nbsp&nbsp";
    $('#countTitle').html(outTitle + inTitle + pointsTitle + rechargeTitle + payTitle);
}
</script>